<template>
	<view>
		<view class="banner">
			<swiper
				class="swiper"
				:indicator-dots="true"
				:autoplay="true"
				circular
				:interval="3000"
				:duration="1000"
			>
				<swiper-item
					class="swiper-item"
					v-for="(item, index) in bannerList"
					:key="index"
				>
					<image class="image-block" :src="item.pic" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="content">
			<view class="tabs">
				<view
					class="item"
					@click="handleTabs(index, item)"
					v-for="(item, index) in tabsList"
					:key="index"
				>
					<view class="icon">
						<image class="image-block" :src="item.icon" mode=""></image>
					</view>
					<view class="text">
						{{ item.name }}
					</view>
				</view>
			</view>
			<view class="title items-center justify-between">
				<view class="left">
					<view class="title-text">充电桩列表</view>
					<view class="title-desc">实时监控充电桩状态</view>
				</view>
				<view class="right">
					<view class="total-count">
						<view class="count-num">{{ pileLast }}</view>
						<view class="count-text">个充电站</view>
					</view>
				</view>
			</view>
			<view class="pile-list">
				<view
					class="pile-item"
					@click="handleListTabs(index, item)"
					v-for="(item, index) in pileDataList"
					:key="index"
				>
					<view class="pile-header">
						<view class="pile-title-wrap">
							<view class="pile-title">{{ item.name }}</view>
							<view class="pile-type">{{ item.address }}</view>
						</view>
						<view class="pile-status-wrap">
							<view>
								<image
									src="@/static/img/daohang.png"
									style="width: 20px; height: 20px"
								></image>
							</view>
							<view class="pile-status"> {{ item.distance }}km </view>
						</view>
					</view>
					<view class="pile-info">
						<view class="info-row">
							<view class="info-item price">
								<text class="value">￥{{ item.price }}/度</text>
							</view>
							<view class="info-item" style="text-align: right">
								<text>闲{{ item.unused }}/{{ item.canUse }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<tabbar :isPages="0"></tabbar>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				pileDataList: [],
				pileLast: 0,
				tabsList: [
					{
						icon: "/static/img/smcd.png",
						name: "扫码充电",
						path: "/pages/tabs/scan",
					},
					{
						icon: "/static/img/myorder.png",
						name: "我的订单",
						path: "/pages/tabs/order",
					},
					{
						icon: "/static/img/wycz.png",
						name: "我要充值",
						path: "/pages/tabs/chong",
					},
					{
						icon: "/static/img/wykp.png",
						name: "我要开票",
						path: "/pages_invoice/invoice/wait-list",
					},
				],
				isTabs: 0,
				dataList: [],
				point: {},
				pageNo: 1,
				bannerList: [],
				last: 1,
			};
		},
		onLoad() {
			this.getPoint();
			this.bannerListFn();
		},
		onReachBottom() {
			console.log("触发底部");
			this.last > this.pageNo ? (this.pageNo++, this.loadData()) : "";
		},
		onPullDownRefresh() {
			this.pageNo = 1;
			this.pileDataList = [];
			this.loadData();
		},
		methods: {
			handleTabs(index, item) {
				index == 1 ? this.switchTab(item.path) : this.navTo(item.path);
			},
			handleListTabs(index, item) {
				this.navTo(
					"/pages/tabs/details?id=" + item.id + "&distance=" + item.distance
				);
			},
			getPoint() {
				let _this = this;
				_this.point.longitude = "116.40";
				_this.point.latitude = "39.90";
				_this.loadData();
			},
			async loadData() {
				const data = {
					uid: uni.getStorageSync("uid"),
					longitude: this.point.longitude,
					latitude: this.point.latitude,
					pageNo: this.pageNo,
					pageSize: "10",
					field2: this.isTabs,
				};
				const res = await this.$request("recharge/list", data, {
					showLoading: true,
				});
				uni.stopPullDownRefresh();
				if (res.result == 0) {
					console.log("data", res);
					this.pileLast = res.data.count;
					this.pileDataList = [...this.pileDataList, ...res.data.list];
					this.last = res.data.last;
					this.pageNo = 1;
				} else {
					this.$util.msg(res.resultNote);
				}
			},
			async bannerListFn() {
				const res = await this.$request("user/slideshow", {});
				console.log("res", res.data);
				if (res.result == 0) { 
					this.bannerList = res.data; // 确保这里赋值是有效的
				} else {
					this.$util.msg(res.resultNote);
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.image-block {
		width: 100%;
		height: 100%;
		display: block;
		border-radius: 10px; /* 圆角效果 */
	}

	.banner {
		width: 100%;
		height: 260rpx;
		.swiper {
			width: 100%;
			height: 100%;
			.swiper-item {
				width: 100%;
				height: 100%;
			}
		}
	}

	.content {
		min-height: 100vh;
		padding: 20rpx;
		padding-bottom: 150rpx;
		// transform: translateY(-50rpx);
		.tabs {
			background: #ffffff;
			border-radius: 20rpx;
			padding: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.item {
				width: 110rpx;
				.icon {
					width: 110rpx;
					height: 110rpx;
				}
				.text {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #222222;
					margin-top: 10rpx;
					text-align: center;
				}
			}
		}
		.title {
			margin: 30rpx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.left {
				.title-text {
					font-size: 36rpx;
					font-weight: bold;
					color: #222222;
					margin-bottom: 8rpx;
				}
				.title-desc {
					font-size: 24rpx;
					color: #999999;
				}
			}
			.right {
				.total-count {
					background: #f5f7fa;
					padding: 12rpx 24rpx;
					border-radius: 30rpx;
					.count-num {
						font-size: 32rpx;
						font-weight: bold;
						color: #2f9e25;
						margin-right: 8rpx;
					}
					.count-text {
						font-size: 24rpx;
						color: #666666;
					}
				}
			}
		}

		.pile-list {
			.pile-item {
				background: #ffffff;
				border-radius: 24rpx;
				padding: 20rpx; /* 调整内边距 */
				margin-bottom: 24rpx;
				box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1); /* 阴影效果 */
				transition: all 0.3s;
				&:active {
					transform: scale(0.98);
					box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
				}
				.pile-header {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 12rpx; /* 调整间距 */
					.pile-title-wrap {
						.pile-title {
							font-size: 38rpx; /* 调整字体大小 */
							font-weight: bold;
							color: #222222;
							margin-bottom: 4rpx; /* 调整间距 */
						}
						.pile-type {
							font-size: 22rpx; /* 调整字体大小 */
							padding: 4rpx 12rpx;
							border-radius: 20rpx;
							display: inline-block;
							background: #e3f2fd; /* 背景色 */
							color: #2196f3; /* 字体颜色 */
						}
					}
					.pile-status-wrap {
						display: flex;
						align-items: center;
						.pile-status {
							font-size: 24rpx;
							padding: 6rpx 20rpx;
							border-radius: 20rpx;
							background: #f5f7fa; /* 背景色 */
							color: #666666; /* 字体颜色 */
						}
					}
				}
				.pile-info {
					.info-row {
						display: flex;
						margin-bottom: 8rpx; /* 调整间距 */
						&:last-child {
							margin-bottom: 0;
						}
						.info-item {
							flex: 1;

							.label {
								font-size: 24rpx;
								color: #999999;
								margin-bottom: 4rpx;
								display: block;
							}
							.value {
								font-size: 28rpx;
								color: #2f9e25; /* 价格字体颜色 */
								font-weight: bold; /* 加粗 */
							}
						}
					}
				}
			}
		}
	}
</style>
